import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            doctor_id: this.$router.params.doctor_id,
            doctor: {
                id: '',
                name: '',
                auth_status: '',
                phone: '',
                head_image: '',
                hospital: '',
                department: '',
                positional_title: '',
                summary: '',
            },
            chats:{
                offset: 0,
                length: 25,
                items: []
            },
        };
        return this.state;
    },
    getDoctor() {
        var me = this;
        var data = {id: me.state.doctor_id};
        var flag = true;
        if(me.beforeGetDoctor) {
            flag = me.beforeGetDoctor(data);
        }
        if(flag) {
            app.get("web/doctor/getDoctor", data, function(res) {
                me.setState({doctor: res.data.result});
                if(me.afterGetDoctor) {
                    me.afterGetDoctor(res);
                }
            });
        }
    },
    listChat() {
        var me = this;
        var data = {doctor_id:me.state.doctor_id,offset: me.state.chats.offset, length: me.state.chats.length};
        app.get("web/dynamic_topic/dynamicList", data, function(res) {
            var chats = me.state.chats;
            var list = res.data.result.list;
            chats.items = chats.items.concat(list);
            me.setState({
                chats:{
                    offset:chats.offset + chats.length,
                    length:chats.length,
                    items:chats.items
                }
            })
        });
    },
    componentWillMount () {
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {
        if(this.init) {
            this.init();
        }
    },
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
